﻿/*
=======================================================
    BillDetail【单据明细】
=======================================================
*/

namespace Services
{
    public interface IBillDetailRepository : IRepository<BillDetail>
    {
    }


    public class BillDetailRepository : BaseRepository<BillDetail>, IBillDetailRepository
    {
        public BillDetailRepository(ISqlSugarClient dB, ICurrentUser currentUser, IQuery<BillDetail> query)
            : base(dB, currentUser, query)
        {
        }

        #region GetPage
        public override (List<BillDetail> items, int totalCount) GetPage(Expressionable<BillDetail> where, int pageIndex = 1, int pageSize = 20, string orderBy = null)
        {
            var fs = _DB.Queryable<BillDetail, Department>
                ((x, d) => new JoinQueryInfos(
                   JoinType.Left, x.DepartmentID == d.DepartmentID
                ))
                .Select((x, d) => new BillDetail
                {
                    BillDetailID = x.BillDetailID.SelectAll(),
                    Department_Name = d.Name
                });

            return _query.GetPage(where, pageIndex, pageSize, orderBy, fs);
        }
        #endregion

        #region GetModel
        public override BillDetail GetModel(Expressionable<BillDetail> where, string orderBy = null)
        {
            var fs = _DB.Queryable<BillDetail, Department>
               ((x, d) => new JoinQueryInfos(
                  JoinType.Left, x.DepartmentID == d.DepartmentID
               ))
               .Select((x, d) => new BillDetail
               {
                   BillDetailID = x.BillDetailID.SelectAll(),
                   Department_Name = d.Name
               });
            return _query.GetModel(where, orderBy, fs);
        }
        #endregion

        #region GetSearch
        public override List<BillDetail> GetSearch(Expressionable<BillDetail> where, string orderBy = null, int? top = null)
        {
            var fs = _DB.Queryable<BillDetail, Department>
              ((x, d) => new JoinQueryInfos(
                 JoinType.Left, x.DepartmentID == d.DepartmentID
              ))
              .Select((x, d) => new BillDetail
              {
                  BillDetailID = x.BillDetailID.SelectAll(),
                  Department_Name = d.Name
              });

            return _query.GetSearch(where, orderBy, top, fs);
        }
        #endregion

    }
}
